package org.hot100_3;

import java.util.HashSet;
import java.util.List;

public class leetcode142 {
    public ListNode detectCycle(ListNode head) {

        ListNode temp = head;

        HashSet<ListNode> set = new HashSet<>();

        while (temp != null) {
            if (set.contains(temp)) {
                return temp;
            }
            set.add(temp);
            temp = temp.next;
        }

        return null;
    }
}
